package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间ID查询床位", notes = "传入房间ID，返回该房间内的所有床位信息")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true, example = "123") @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    /**
     * 新建床位
     * @param bedDto
     * @return
     */
    @ApiOperation("新增床位")
    @ApiImplicitParam(name="bedDto",value = "床位信息",required = true,dataType = "BedDto")
    @ApiOperationSupport(includeParameters = {"bedDto.bedNumber","bedDto.sort","bedDto.roomId"})
    @PostMapping("/create")
    public ResponseResult createBed(@ApiParam(value = "床位信息", required = true) @RequestBody BedDto bedDto){
        bedService.createBed(bedDto);
        return success();
    }

    /**
     * 根据Id查询床位
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据床位ID查询床位信息", notes = "传入床位ID，返回对应的床位详细信息")
    public ResponseResult getBedById(@ApiParam(value = "床位ID", required = true, example = "456") @PathVariable Integer id){
        BedVo bedVo = bedService.getBedById(id);
        return success(bedVo);
    }

    /**
     * 更新床位
     * @param bedDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新床位信息", notes = "传入床位信息，更新数据库中的床位记录")
    public ResponseResult updateBed(@ApiParam(value = "床位信息", required = true) @RequestBody BedDto bedDto){
        bedService.updateBed(bedDto);
        return success();
    }

    /**
     * 根据Id删除床位
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据床位ID删除床位", notes = "传入床位ID，从数据库中删除对应的床位记录")
    public ResponseResult deleteBedById(@ApiParam(value = "床位ID", required = true, example = "789") @PathVariable Integer id){
        bedService.deleteBedById(id);
        return success();
    }
}